import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore(
  "userStore",
  () => {
    // 定义状态
    const userData = ref<Record<string, any> | null>(null);
    const exchangeRateData = ref<Record<string, any> | null>(null);
    const exchangeRateDate = ref<string | null>(null);

    // 定义操作
    const setUserData = (newUserData: Record<string, any> | null) => {
      userData.value = newUserData;
    };

    const setExchangeRateData = (newExchangeData: Record<string, any> | null, newDate: string) => {
      exchangeRateData.value = newExchangeData;
      exchangeRateDate.value = newDate;
    };

    return {
      userData,
      setUserData,
      exchangeRateData,
      exchangeRateDate,
      setExchangeRateData
    };
  },
  {
    persist: true
  }
);
